<template>
	<view class="cart-container">
		<!-- 购物车商品列表的标题区域 -->
		<view class="cart-title">
			<!-- 左侧的图标 -->
			<uni-icons type="shop" size="18"></uni-icons>
			<!-- 描述文本 -->
			<text class="cart-title-text">购物车</text>
		</view>
		<my-address></my-address>
		<uni-swipe-action>
			<block v-for="item in cart" :key='item.goods_id'>
				<uni-swipe-action-item  :right-options="options"  @click="delCartItem(item.goods_id)">
					<my-goods :goodsInfo='item' showRadio showNumber></my-goods>
				</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<view class="empty" :style="{height: emptyHeight + 'px'}" v-if="cart.length===0">购物车为空</view>
		<my-settle></my-settle>
	</view>
</template>

<script>
	import badgeMix from '@/mixins/tabbar-badge.js'
	import {
		mapState,mapMutations
	} from 'vuex'
	export default {
		mixins: [badgeMix],
		computed: {
			// 将 m_cart 模块中的 cart 数组映射到当前页面中使用
			...mapState('cartModule', ['cart']),
		},
		data() {
			return {
				options: [{
					text: '删除',
					style: {
						backgroundColor: '#dd524d'
					}
				}],
				emptyHeight:0
			};
		},
		onLoad() {
			let systemInfo = uni.getSystemInfoSync()
			this.emptyHeight = systemInfo.windowHeight - 180
		},
		methods: {
			...mapMutations('cartModule', ['delCartItem']),
		}
	}
</script>

<style lang="scss">
	.cart-container{
		padding-bottom: 50px;
	}
	.cart-title {
		height: 40px;
		display: flex;
		align-items: center;
		font-size: 14px;
		padding-left: 5px;
		border-bottom: 1px solid #efefef;

		.cart-title-text {
			margin-left: 10px;
		}
	}
	.empty{
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 40px;
			color: #ccc;
	}
</style>
